package com.yf.service.meetingUser.impl;

import com.yf.dao.meetingUser.AuctionDao;
import com.yf.entity.meetingUser.AuctionEntity;
import com.yf.service.impl.BaseServiceImpl;
import com.yf.service.meetingUser.AuctionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * 拍卖Service实现类
 *
 * @author hxf
 * @email 505860922@qq.com
 * @date Fri Dec 14 15:54:30 CST 2018
 */
@Service
public class AuctionServiceImpl extends BaseServiceImpl<AuctionEntity> implements AuctionService {
    @Autowired
    private AuctionDao auctionDao;



    /**内部方法**/


    /**外部方法实现**/
    @Override
    public List<AuctionEntity> getAll() {
        return auctionDao.getAll();
    }

    @Override
    public void deleteById(Long aId) {
        auctionDao.deleteById(aId);
    }

    @Override
    public List<AuctionEntity> getByStatus(Integer status) {
        return auctionDao.getByStatus(status);
    }

    @Override
    @Transactional
    public void saveAuction(AuctionEntity auctionEntity) {
        List<AuctionEntity> list = auctionDao.getByStatus(0);
        List<Long> ids = new ArrayList<>();
        if(!list.isEmpty()){
            for (AuctionEntity entity : list) {
                ids.add(entity.getId());
            }
        }

        auctionDao.updateStatus(ids);

        auctionDao.save(auctionEntity);

    }
}
